﻿using FluentNHibernate.Conventions.Instances;

namespace HashFoo.Nhib
{
    public class PropertyLengthConvention : FluentNHibernate.Conventions.IPropertyConvention
    {
        /// <summary>
        /// Apply changes to the target
        /// </summary>
        public void Apply(IPropertyInstance instance)
        {
            // this defaults everything binary to (MAX).  Types default to "var*", so in theory, this doesn't waste space.
            // if performance needs to be optimized, provide an override to the automapping.
            // the sperate value for byte[] is probably not needed... but there just in case.
            // DMF - 20101103

            if (instance.Type.GetUnderlyingSystemType().Equals(typeof(byte[]))) instance.Length(int.MaxValue);
            if (instance.Type.GetUnderlyingSystemType().Equals(typeof(string))) instance.Length(256);
        }
    }
}